############################################
###### Replication Code for Table A4  ######
########### January 9th, 2025 ##############
############################################

rm(list=ls())

### Script produces Table A4 and saves it in the `/tables` folder

# load libraries
library(fixest)
library(modelsummary)

# load main data
df <- readRDS("data/workfile.rds")

# convert NA to dummy = 1
df$trust_missing <- ifelse(is.na(df$trust_in_opposing_parties), 1, 0)

# Use dummy as DV
m1 <- feols(trust_missing ~ treated_econ + treated_culture, df, se = "iid") %>% 
  summary()
m1_fe <- feols(trust_missing ~ treated_econ + treated_culture | dem_country_code, df, se = "iid") %>% 
  summary()

# Produce table
modelsummary(list("(1)" = m1, "(2)" = m1_fe), stars = T)
modelsummary(list("(1)" = m1, "(2)" = m1_fe), stars = T, 
             coef_omit = "dem_country_code*",
             title = "Predicting missingness in DV",
             coef_rename = c("household_incomelow" = "Low HH inc", 
                             "household_incomemedium" = "Medium HH inc",
                             "household_incomePrefer not to say" = "HH inc missing",
                             "mean_outparty_feeling" = "Average Out-Party Feeling",
                             "dem_age" = "Age", 
                             "age_sq" = "Age squared",
                             "dem_gendermale" = "Male",
                             "dem_education_levellow" = "Low education", 
                             "dem_education_levelmedium" = "Medium education",
                             "dem_education_levelno" = "No education", 
                             "dem_city_or_ruralrural" = "Rural",
                             "lrscale" = "Left-right scale",
                             "treated_culture" = "Cultural issues treatment", 
                             "treated_econ" = "Economic issues treatment",
                             "political_interest_num" = "Political Interest (1-5)",
                             "high_pol_interest" = "High political interest"),
             add_rows = data.frame(t(c("Country-FE included", "no", "yes"))),
             output = "tables/TabA4_predicting_missing_DV.docx")
